package game.players.goalkeeper.opp;



import com.uqbar.vainilla.appearances.Sprite;

import game.ball.Possessed;
import game.ball.SoccerBall;
import game.players.goalkeeper.Goalkeeper;
import game.soccerField.Arc;

public class GoalkeeperCPUOpp extends Goalkeeper{
	
	public GoalkeeperCPUOpp(int x,int y) {
		super(x, y);
		this.setStationarySprite(Sprite.fromImage("/images/arquero_arco.png").crop(21, 11, 84, 77));
		this.setAppearance(this.getStationarySprite());
		this.setState(new GoalkeeperWithoutBallOpp(this));
	}
	
	public GoalkeeperCPUOpp(int x,int y,Arc rightArc) {
		super(x, y);
		this.setStationarySprite(Sprite.fromImage("/images/arquero_arco.png").crop(21, 11, 84, 77));
		this.setAppearance(this.getStationarySprite());
		this.setState(new GoalkeeperWithoutBallOpp(this));
		this.setArc(rightArc);
	}

	@Override
	public void onSceneActivated() {
		this.setArc(this.getScene().getRightArc());
		super.onSceneActivated();
	}
	
	public void updateProperLocation() {
		this.getProperLocation().setLocation(this.getArc().getX()-100,
				this.getArc().getY()+this.getArc().getAppearance().getHeight()/2);
	}

	@Override
	public void setRightAnimationWithSpeed(double meanTime) {
	}

	@Override
	public void setLeftAnimationWithSpeed(double meanTime) {
	}

	@Override
	public boolean isUserMate() {
		return false;
	}

	@Override
	public void takeTheBall() {
		SoccerBall ball = this.getScene().getSoccerBall();
		double advanceX = this.getX() - ball.getX();
		double advanceY = this.getY() + this.getAppearance().getHeight() - ball.getY() - ball.getRatio();
		
		ball.moveNormally(advanceX, advanceY);
		
		if(!ball.isFree())
			ball.getPlayer().loseTheBall();
		
		this.setState(new GoalkeeperWithBallOpp(this));
		ball.setState(new Possessed(this));		
	}


}
